package com.zecan.blog.controller;

import com.zecan.blog.common.BlogResult;
import com.zecan.blog.service.ChattingRecordsService;
import com.zecan.blog.utils.BlogResultUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zecan
 * @Description:
 * @ClassName: ChattingRecordsController
 * @date 2022/12/20 15:42
 */

@RestController
@RequestMapping("/chatting")
public class ChattingRecordsController {

    @Resource
    private ChattingRecordsService chattingRecordsService;


    @RequestMapping(value = "/record_list",method = RequestMethod.POST)
    public BlogResult getChattingRecords(Integer loginUserId, Integer friendUserId) {
        return BlogResultUtils.ok(chattingRecordsService.getChattingRecords(loginUserId, friendUserId),"获取聊天记录成功");
    }

    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/record_list_limit" , method = RequestMethod.GET)
    public BlogResult getRecordsLimit(Integer offset, Integer limit) {
        return BlogResultUtils.ok(chattingRecordsService.getBgChatRecordVo(offset, limit),"获取聊天记录成功");
    }
    @PreAuthorize("hasAnyAuthority('admin')")
    @RequestMapping(value = "/del" , method = RequestMethod.GET)
    public BlogResult delRecord(Integer recordId) {
        chattingRecordsService.delRecord(recordId);
        return BlogResultUtils.ok("删除聊天记录成功");
    }
}
